package edu.gdin.ecommerce.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import edu.gdin.ecommerce.dao.CustomerDAO;
import edu.gdin.ecommerce.model.Customer;
import edu.gdin.ecommerce.service.ICustomerService;
import edu.gdin.ecommerce.util.Pager;

@Service("customerService")
public class CustomerService implements ICustomerService {

	private CustomerDAO customerDAO;
	
	public CustomerDAO getCustomerDAO() {
		return customerDAO;
	}

	@Resource(name="customerDAO")
	public void setCustomerDAO(CustomerDAO customerDAO) {
		this.customerDAO = customerDAO;
	}


//	@Override
	public boolean addCustomer(Customer customer) {
		if(!customerDAO.isExist(Customer.class, "certificateNo", customer.getCertificateNo())){
			try{
				customerDAO.insert(customer);
				return true;
			}catch(Exception e){
				e.printStackTrace();
				return false;
			}
		}
		return false;
	}
	
	public Pager queryCustomer(Customer customer, String from, String to, Integer cPage){
			return this.customerDAO.queryCustomer(customer, from, to, cPage);
	}

	
//	@Override
	public boolean updateCustomer(Customer customer) {
		try {
			this.customerDAO.update(customer);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

//	@Override
	public Customer getCustomerById(Integer customerId) {
		return (Customer) customerDAO.findByPk(Customer.class, customerId);
	}
}
